/**
 * 
 */
package src.knock;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @author javaOne
 *
 */
public class KKMultiServer {

	/**
	 * 
	 */
	static Map parametrosX = new HashMap();
	
	public static ServerSocket serverSocketX;
	public static Socket clientSocketX;
	public static PrintWriter outX = null;
	public static BufferedReader inX = null;
	public KKMultiServer(Map parametros) {
		// TODO Auto-generated constructor stub
		this.parametrosX = parametros;
		/*
		if (parametros !=null){
	    	System.out.println("parametros.size()::: " + parametros.size());
	    	String cadena = "";
	    	for(int i = 1; i <= parametros.size() ; i++){
	    		cadena = null;
	    		cadena = (String)parametros.get("LINEA" + i);
	    	}
	    	cadena = "101";
			
	    }else{
	    	// no tiene parametros es null
	    	parametros = new HashMap(); 
	    } 	
	    */	
	}
	public void prepararAmbienteSocketServidor() throws IOException{
		if (parametrosX !=null){

	    	System.out.println("parametros.size()::: " + parametrosX.size());
	    	String cadenaEnviar = "";
	    	prepararServerSocket();
	    	

		}
	}
	
	public static void prepararServerSocket() throws IOException{
        try {
			boolean listening = true;
            serverSocketX = new ServerSocket(4444);
            System.out.println("Socker Abierto. " + serverSocketX.getInetAddress().getHostName());	 
            while (listening)
	        	new KKMultiServerThread(serverSocketX.accept(),parametrosX).start();
        	
            serverSocketX.close();
            
        } catch (IOException e) {
            System.err.println("No se ha podido escuchar en el puerto 4444.");
            System.exit(-1);
        }
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args)  throws IOException {
		// TODO Auto-generated method stub
		/*
        ServerSocket serverSocket = null;
        boolean listening = true;

        try {
            serverSocket = new ServerSocket(4444);
            System.out.println("Socker Abierto. " + serverSocket.getInetAddress().getHostName());
        } catch (IOException e) {
            System.err.println("No se ha podido escuchar en el puerto 4444.");
            System.exit(-1);
        }

        while (listening)
        	new KKMultiServerThread(serverSocket.accept()).start();
        	
        serverSocket.close();
        */
	}

}
